<html>
<head>
	<title>芭蕉花管理平台-众筹单管理</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="SHORTCUT ICON" href="/img/favicon.ico">
	<script type="text/javascript">
		var pathname = window.location.pathname;
		if (pathname != "/mobile/home.html") {
			location.href = '/';
		}
	</script>
	<style type="text/css">
		.search-box.condition-hidden .search-condition {display: none;}
		.btn {appearance: none; -moz-appearance: none; -webkit-appearance: none;}
		.card {border-radius: 0; border-left: 0; border-right: 0; overflow: visible;}
		.card-header {padding: 0;border-radius: 0; background-color: #fff;}
		.card-header .btn {border-radius: 0; background-color: rgba(0,0,0,.03);}
		.card-header .btn.collapsed {background-color: #fff;}
		.card-body {padding: 0.5rem;}
		.card-bill-img-box {text-align: center; padding-bottom: 0.25rem;}
		.card-bill-img {width: 4rem; height: 4rem; padding : 2px; box-shadow: 1px 2px 10px #bbb;}
		.card-title {font-size: 1rem; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.25rem;}
		.card-info {font-size: .875em; color: #777;}
		.card-user {font-size: .875em; color: #777}
		.card-money {font-size: .875em; color: #777}
		.card-info .type {display: inline-block; width: 50%; text-align: left;}
		.card-info .date {display: inline-block; width: 50%; text-align: right;}
		.card-user .account {display: inline-block; width: 50%; text-align: left;}
		.card-user .name {display: inline-block; width: 50%; text-align: right;}
		.card-money .bill {display: inline-block; width: 50%; text-align: left;}
		.card-money .amount {display: inline-block; width: 50%; text-align: right;}
		.card-status .status {padding: .25rem;}
		ul.card-opt {display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; padding: 0; margin: 0; border-top: 1px solid #ccc;}
		ul.card-opt>li {position: relative; display: block; padding-top: 3em; -webkit-box-flex: 1; -webkit-flex: 1 0 auto; -ms-flex: 1 0 auto; flex: 1 0 auto;}
		ul.card-opt>li:active {background: rgba(0,123,255,.15);}
		ul.card-opt>li>i {position: absolute; top: .25em; left: 0; right: 0; display: block; text-align: center; line-height: 1em; font-size: 2em;}
		ul.card-opt>li>span {display: block; text-align: center;}
		#dataInfo {margin-top: .5rem; font-size: .6rem; color: #777; text-align: right;}
		#pageList {margin-top: 1.25rem;}
		#pageList nav {display: inline-block;}
		#pageList .page-link:hover {z-index: 2; color: #007bff; text-decoration: none; background-color: #fff; border-color: #dee2e6;}
		#pageList .page-link:active {z-index: 2; color: #0056b3; text-decoration: none; background-color: #e9ecef; border-color: #dee2e6;}
		#pageList .page-link:focus {box-shadow: none;}
	</style>
</head>
<body>
	<div class="container">
		<nav aria-label="breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item"><a href="#" onclick="goMenu();return false;"><i class="fa fa-chevron-left"></i><span style="padding-left: 10px;">菜单</span></a></li>
				<li class="breadcrumb-item active" aria-current="page">用户众筹列表</li>
			</ol>
		</nav>
		<div class="row collapse" id="searchBox">
			<div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
				<div class="form-group">
					<select class="form-control" id="searchSort">
						<option value="2">降序</option>
						<option value="1">升序</option>
					</select>
				</div>
			</div>
			<div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
				<div class="form-group">
					<select class="form-control" id="searchStatus">
						<option value="">选择状态</option>
						<option value="0">待审核</option>
						<option value="1">进行中</option>
						<option value="2">付款中</option>
						<option value="3">已结束</option>
						<option value="4">进行中(已扣分) </option>
						<option value="5">已驳回</option>
						<option value="6">已失效</option>
<!-- 						<option value="21">付款中(暂停付款)</option> -->
						<option value="22">进行中(已证明)</option>
					</select>
				</div>
			</div>
			<div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
				<div class="form-group">
					<select class="form-control" id="searchCardType">
						<option value="">选择收款银行卡类别</option>
						<option value="1">储蓄卡</option>
						<option value="2">支付宝</option>
					</select>
				</div>
			</div>
			<div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
				<div class="form-group">
					<select class="form-control" id="searchType">
						<option value="">选择类型</option>
						<option value="1">江湖救急</option>
						<!--<option value="2">还房贷</option>-->
						<!--<option value="3">还车贷</option>-->
						<!--<option value="4">还信用卡</option>-->
						<option value="5">求助</option>
					</select>
				</div>
			</div>
			<div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
				<div class="form-group">
					<input type="text" id="searchCrowd" class="form-control" placeholder="输入标题/发单人/用户账号/筹集金额搜索"/>
				</div>
			</div>
			<div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
				<div class="form-group">
					<button type="button" onclick="search();"  class="btn btn-block btn-primary">搜索</button>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-xl-12">
				<div class="form-group">
					<a type="button" id="searchBoxCollapse" class="btn btn-block btn-light" data-toggle="collapse" data-target="#searchBox" aria-expanded="false" aria-controls="searchBox"><span style="padding-right: 1rem; font-size: 0.875rem; color: #999;">搜索条件</span><i class="fa fa-angle-double-down text-primary" aria-hidden="true"></i> <i class="fa fa-angle-double-up text-primary" aria-hidden="true"></i></a>
				</div>
			</div>
		</div>
		
		<div class="row">
			<div class="col-xl-12">
				<div class="accordion" id="crowdfundBox">
				</div>
			</div>
		</div>
		<div id="dataInfo">
		</div>
		
		<div class="row" id="pageList" style="display: none;">
			<div class="col-xl-12 text-center">
				<nav aria-label="...">
					<ul class="pagination">
						<li class="page-item previous disabled">
							<a class="page-link" href="#" onclick="goPrevious();return false;">上一页</a>
						</li>
						<li class="page-item next disabled">
							<a class="page-link" href="#" onclick="goNext();return false;">下一页</a>
						</li>
					</ul>
				</nav>
			</div>
		</div>
	</div>

<!-- 【信用扣分】弹出窗内容 -->
<div class="modal fade" id="punishDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title" align="center" >信用扣分处罚</h4>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<div class="modal-body">
				<form>
					<div class="form-group">
						<label for="punishScore" style="color: red;">*扣除分数：</label>
						<select id="punishScore" class="form-control">
							<option value="-5">5</option>
							<option value="-10">10</option>
							<option value="-15">15</option>
							<option value="-20">20</option>
							<option value="-25">25</option>
							<option value="-30">30</option>
							<option value="-35">35</option>
							<option value="-40">40</option>
							<option value="-45">45</option>
							<option value="-50">50</option>
						</select>
					</div>
					<div class="form-group">
						<label for="reason" style="color: red;">*扣分原因：</label>
						<textarea id="reason" name="reason" rows="4" style="width: 100%;"></textarea>
					</div>
					<div class="form-group">
						<label for="selReason" style="color: #0aa66e;">常用原因：</label>
						<select id="selReason" class="form-control" onchange="selText()">
							<option value="">--请选择--</option>
							<option value="上传账单与实际消费不符合">上传账单与实际消费不符合</option>
							<option value="账单不真实">账单不真实</option>
							<option value="账单图片模糊">账单图片模糊</option>
							<option value="不是本人账单">不是本人账单</option>
						</select>
					</div>
				</form>
			</div>
			<div class="modal-footer" style="display: block;text-align: center;">
				<button type="button" class="btn btn-light" style="width: 40%; max-width: 10em;" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-info" style="width: 40%; max-width: 10em;" onclick="confirmSubmit();">确定</button>
			</div>
		</div>
	</div>
</div>

<!-- 【驳回】弹出窗内容 -->
<div class="modal fade" id="rejectDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title" align="center">众筹单驳回</h4>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<div class="modal-body">
				<form>
					<div class="form-group">
						<label for="rejectResion" style="color: red;">*驳回原因：</label>
						<textarea id="rejectResion" name="rejectResion" rows="4" style="width: 100%" ></textarea>
					</div>
					<div class="form-group">
						<label for="selRejectReason" style="color: #0aa66e;">常用原因：</label>
						<select id="selRejectReason" class="form-control" onchange="selRejectText()">
							<option value="">--请选择--</option>
							<option value="上传账单与实际消费不符合">上传账单与实际消费不符合</option>
							<option value="账单不真实">账单不真实</option>
							<option value="账单图片模糊">账单图片模糊</option>
							<option value="不是本人账单">不是本人账单</option>
						</select>
					</div>
				</form>
			</div>
			<div class="modal-footer" style="display: block; text-align: center;">
				<button type="button" class="btn btn-light" style="width: 40%; max-width: 10em;" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-info" style="width: 40%; max-width: 10em;" onclick="confirmReject();">确定</button>
			</div>
		</div>
	</div>
</div>

<!-- page script -->
<script>
	var maxCount = 10;
	var totalPages = 0;
	var page = 1;
	var searchClick = false;

	// 取得通过html传递的参数
	var paramPage = getHtmlParams("page");
	if (paramPage != null) {
		page = paramPage;
	}
	var paramSearchSort = getHtmlParams("searchSort");
	if (paramSearchSort != null) {
		$("#searchSort").val(paramSearchSort);
	}
	var paramSearchStatus = getHtmlParams("searchStatus");
	if (paramSearchStatus != null) {
		$("#searchStatus").val(paramSearchStatus);
	}
	var paramSearchCardType = getHtmlParams("searchCardType");
	if (paramSearchCardType != null) {
		$("#searchCardType").val(paramSearchCardType);
	}
	var paramSearchCrowd = getHtmlParams("searchCrowd");
	if (paramSearchCrowd != null) {
		$("#searchCrowd").val(paramSearchCrowd);
	}
	var paramSearchType = getHtmlParams("searchType");
	if (paramSearchType != null) {
		$("#searchType").val(paramSearchType);
	}
	// 取后清空
	clearHtmlParams();

	$(document).ready(function() {
		//加载数据
		getCrowdfund();
	});

	function goMenu() {
		getHtml('/mobile/menu.html');
	}

	function search() {
		searchClick = true;
		totalPages = 0;
		page = 1;
		getCrowdfund();
	}
	
	function goPrevious() {
		if (page > 1) {
			page = page - 1;
			getCrowdfund();
		}
	}
	
	function goNext() {
		if (page < totalPages) {
			page = page + 1;
			getCrowdfund();
		}
	}

	function getCrowdfund(){
		var searchSort = $("#searchSort").val();
		if (searchSort == '2') {
			searchSort = 'desc';
		} else {
			searchSort = '';
		}
		var searchStatus = $("#searchStatus").val();
		var searchCardType = $("#searchCardType").val();
		var searchCrowd = $("#searchCrowd").val();
		var searchType = $("#searchType").val();
		var startIndex = (page - 1) * maxCount;

		var url = "/crowdfund/getCrowdfundList";
		params = {
				"sort" : searchSort,
				"status" : searchStatus,
				"cardType" : searchCardType,
				"keyWord" : searchCrowd,
				"flag" : searchType,
				"start" : startIndex,
				"length" : maxCount,
				"draw" : page
		};
		getMapData(url, params, function(data, result) {
			if (result == "success") {
				var dataList = data.data;
				var totalCount = data.recordsTotal;
				if ((totalCount % maxCount) > 0) {
					totalPages = parseInt(totalCount / maxCount) + 1;
				} else {
					totalPages = parseInt(totalCount / maxCount);
				}
				if (page <= 1) {
					$("#pageList .previous").addClass("disabled");
				} else {
					$("#pageList .previous").removeClass("disabled");
				}
				if (page >= totalPages) {
					$("#pageList .next").addClass("disabled");
				} else {
					$("#pageList .next").removeClass("disabled");
				}
				if (totalPages <= 1) {
					$("#pageList").hide();
				} else {
					$("#pageList").show();
				}

				var dataHtml = '';
				for (let i = 0; i < dataList.length; i++) {
					let dataRecord = dataList[i];
					let id = dataRecord.id;
					let uid = dataRecord.uid;
					let img = dataRecord.img;
					let imgUrls;
					if (img != '') {
						imgUrls = img.split("$");
					} else {
						imgUrls = new Array("");
					}
					let type = dataRecord.type;
					let typeStr = "";
					if(type == 1){
						typeStr = "江湖救急"
					} else if(type == 2){
						typeStr = "还房贷";
					} else if(type == 3){
						typeStr = "还车贷";
					} else if(type == 4){
						typeStr = "还信用卡";
					} else if(type == 5){
						typeStr = "求助";
					}
					let status = dataRecord.status;
					let entTime = toDate(dataRecord.endTime).format('yyyy-MM-dd')

					dataHtml += '<div class="card" id="crowdfund' + i + '">';
					dataHtml += '<div class="card-header" id="crowdfundHeader' + i + '">';
					dataHtml += '<div>';
					dataHtml += '<div class="btn btn-block text-left collapsed" type="button" data-toggle="collapse" data-target="#crowdfundCollapse' + i + '" aria-expanded="true" aria-controls="crowdfundCollapse' + i + '">';
					dataHtml += '<div class="card-title">' + dataRecord.title + '</div>';
					dataHtml += '<div class="card-info"><span class=type>' + typeStr + '</span><span class="date">' + entTime + '</span></div>';
					dataHtml += '<div class="card-user"><span class="account">' + dataRecord.userAccount + '</span><span class="name">' + dataRecord.partyName + '</span></div>';
					dataHtml += '<div class="card-money"><span class="bill">' + dataRecord.billMoney + '</span><span class="amount">' + dataRecord.currentMoney + '/' + dataRecord.targetMoney + '</span></div>';
					if (status == 0) {
						dataHtml += '<div class="card-status"><span class="status badge badge-primary">待审核</span></div>';
					} else if (status == 1) {
						dataHtml += '<div class="card-status"><span class="status badge badge-success">进行中</span></div>';
					} else if (status == 2) {
						dataHtml += '<div class="card-status"><span class="status badge badge-warning">付款中</span></div>';
					} else if (status == 3) {
						dataHtml += '<div class="card-status"><span class="status badge badge-secondary">已完成</span></div>';
					} else if (status == 4) {
						dataHtml += '<div class="card-status"><span class="status badge badge-success">进行中(已扣分)</span></div>';
					} else if (status == 5) {
						dataHtml += '<div class="card-status"><span class="status badge badge-danger">已驳回</span></div>';
					} else if (status == 6) {
						dataHtml += '<div class="card-status"><span class="status badge badge-secondary">已失效</span></div>';
					} else if (status == 21) {
						dataHtml += '<div class="card-status"><span class="status badge badge-warning">付款中(暂停付款)</span></div>';
					} else if (status == 22) {
						dataHtml += '<div class="card-status"><span class="status badge badge-success">进行中(已证明)</span></div>';
					}

					dataHtml += '</div>';
					dataHtml += '</div>';
					dataHtml += '</div>';
					
					dataHtml += '<div id="crowdfundCollapse' + i + '" class="collapse" aria-labelledby="crowdfundHeader' + i + '" data-parent="#crowdfundBox">';
					dataHtml += '<div class="card-body">';
					dataHtml += '<div class="card-bill-img-box">';
					for (let j = 0; j < imgUrls.length; j++) {
						dataHtml += '<img src="' + imgUrls[j] + '" class="card-bill-img" onclick="maxImg(' + "'" + imgUrls[j] + "'" + ",'" + '账单' + "'" + ')" alt="账单">';
					}
					dataHtml += '</div>';
					
					dataHtml += '<ul class="card-opt">';
					if (status == 0 || status == 22) {
						dataHtml += '<li class="text-success" onclick="checkPass(' + id + ')"><i class="fa fa-check"></i><span>通过</span></li>';
					}
					if (status == 1 || status == 22) {
						dataHtml += '<li class="text-danger" onclick="checkNotPass(' + id + ', ' + uid + ')"><i class="fa fa-remove"></i><span>扣分</span></li>';
					}
					if (status == 0) {
						dataHtml += '<li class="text-primary" onclick="checkBack(' + id + ', ' + uid + ')"><i class="fa fa-repeat"></i><span>驳回</span></li>';
					}
					dataHtml += '<li class="text-secondary" onclick="viewDetail(' + id + ')"><i class="fa fa-file-text-o"></i><span>详情</span></li>';
					dataHtml += '</ul>';
					
					dataHtml += '</div>';
					dataHtml += '</div>';
					
					
					dataHtml += '</div>';
				}
				$("#crowdfundBox").html(dataHtml);
				if (totalCount > 0) {
					let startNum = startIndex + 1;
					let endNum = startIndex + dataList.length;
					$("#dataInfo").html('从 ' + startNum + ' 到 ' + endNum + ' /共 ' + totalCount + ' 条数据');
					if (searchClick) {
						$("#searchBoxCollapse").click();
					}
				} else {
					$("#dataInfo").html('没有检索到数据');
				}
				document.body.scrollTop = document.documentElement.scrollTop = 0;
				for (let i = 0; i < dataList.length; i++) {
					$("#crowdfundCollapse" + i).on('show.bs.collapse', function () {
						$(this).parent().attr("style", "overflow: visible; z-index: 1; box-shadow: 1px 2px 10px #2aaf98;");
					});
					$("#crowdfundCollapse" + i).on('hide.bs.collapse', function () {
						$(this).parent().removeAttr("style");
					});
				}
			}
			searchClick = false;
		}, true);
	}

	//众筹信息审核通过
	function checkPass(id){
		showConfirmBox("确定审核通过该众筹单？", function(result) {
			if (result == "yes") {
				changeStatus(id,1);
			}
		});
	}
	//付款中->暂停付款
	function pausePay(id){
		showConfirmBox("确定暂停付款？", function(result) {
			if (result == "yes") {
				changeStatus(id,21);
			}
		});
	}
	//暂停付款->付款中
	function resumePay(id){
		showConfirmBox("确定恢复付款？", function(result) {
			if (result == "yes") {
				changeStatus(id,2);
			}
		});
	}
	//提交审核通过
	function changeStatus(id,status) {
		let url = "/crowdfund/editCrowdfundStatus";
		let params = {
				"id" : id,
				"status" : status
		};
		getMapData(url, params, function(data, result) {
			if (result == "success") {
				getCrowdfund();
			}
		}, true);
	}
	//上传的账单信息不通过，弹出扣分界面
	var cid ;
	var usid;
	function checkNotPass(crowdfundId,uid){
		$("#punishDialog").modal("toggle");
		cid = crowdfundId;
		usid = uid;
	}

	//确定处罚扣分
	function confirmSubmit() {
		var reso = $("#reason").val();
		if( $.trim(reso)  == ""){
			showErrorMessageTip("扣分原因不能为空", "reason");
			return ;
		}
		//1、通过审核
		// submitCheck(cid,4);
		//2、进行信用分扣除
		let url = "/crowdfund/editCreditScoreByUserId";
		let params = {
				"userId" : usid,
				"score" : $("#punishScore").val(),
				"reason" : $("#reason").val(),
				"cid" :cid,
				"status" :4,
				"id" : cid,
				"type" : 5   //信用类型(1发红包 2互助 3登录 4其他 5违规)
		};
		getMapData(url, params, function(data, result) {
			if (result == "success") {
				 $("#punishDialog").modal("toggle");
				getCrowdfund();
			}
		});
	}

	//驳回弹框
	var bcid ;
	function checkBack(crowdfundId,uid){
		$("#rejectDialog").modal("toggle");
		bcid = crowdfundId;
	}
	//确定驳回
	function confirmReject() {
		var reso = $("#rejectResion").val();
		if( $.trim(reso)  == ""){
			showErrorMessageTip("驳回原因不能为空", "rejectResion");
			return ;
		}

		let url = "/crowdfund/updCrowd";
		let params = {
				"rejectResion" : reso,
				"cid" :bcid,
				"status" :5
		};
		getMapData(url, params, function(data, result) {
			if (result == "success") {
				$("#rejectDialog").modal("toggle");
				getCrowdfund();
			}
		});
	}

	//查看众筹单筹款详情
	function viewDetail(id){
		var searchSort = $("#searchSort").val();
		var searchStatus = $("#searchStatus").val();
		var searchCardType = $("#searchCardType").val();
		var searchCrowd = $("#searchCrowd").val();
		var searchType = $("#searchType").val();
		let url = "/mobile/pages/crowdfund/crowdfundDetail.html";
		let params = {
				"htmlParams": [
						{
							"key" : "crdId",
							"value" : id
						},
						{
							"key" : "page",
							"value" : page
						},
						{
							"key" : "searchSort",
							"value" : searchSort
						},
						{
							"key" : "searchStatus",
							"value" : searchStatus
						},
						{
							"key" : "searchCardType",
							"value" : searchCardType
						},
						{
							"key" : "searchCrowd",
							"value" : searchCrowd
						},
						{
							"key" : "searchType",
							"value" : searchType
						}
				]
		}
		getHtml(url, params);
	}

	//选择常用扣分理由
	function selText() {
		var sel = $("#selReason").val();
		$("#reason").val(sel);
	}

	//选择常用驳回理由
	function selRejectText() {
		var sel = $("#selRejectReason").val();
		$("#rejectResion").val(sel);
	}

</script>
</body>
</html>
